
	
function Notification(msg, type){
	var box = $('<div class="' + type + '"><div class="close"></div><div class="icon"></div>' + msg + '</div>').hide();
	
	$('#notification').prepend(box);
	
	if(type != 'warning'){	
		box.fadeIn(500).delay(10000).fadeOut(500, function(){
			box.remove();	
		});
	}else{
		box.fadeIn(500);	
	}
	
	box.find('.close').on('click', function(){
		box.stop().fadeOut(500, function(){
			box.remove();	
		});	
	});
}

function addToCart(product_id, quantity) {
	quantity = typeof(quantity) != 'undefined' ? quantity : 1;

	$.ajax({
		url: 'index.php?route=checkout/cart/add',
		type: 'post',
		data: 'product_id=' + product_id + '&quantity=' + quantity,
		dataType: 'json',
		success: function(json) {
			if (json['redirect']) {
				location = json['redirect'];
			}
			
			if (json['success']) {
				Notification(json['success'], 'success');
				
				$('#cart-total').html(json['total']);
				$('.cart').load('index.php?route=module/cart .cart > *');
			}	
		}
	});
}



function addToWishList(product_id) {
	$.ajax({
		url: 'index.php?route=account/wishlist/add',
		type: 'post',
		data: 'product_id=' + product_id,
		dataType: 'json',
		success: function(json) {		
			if (json['success']) {
				Notification(json['success'], 'success');

				$('#wishlist-total').html(json['total']);
			}	
		}
	});
}

function addToCompare(product_id) { 
	$.ajax({
		url: 'index.php?route=product/compare/add',
		type: 'post',
		data: 'product_id=' + product_id,
		dataType: 'json',
		success: function(json) {	
			if (json['success']) {
				Notification(json['success'], 'success');
				
				$('#compare-total').html(json['total']);
			}	
		}
	});
}

$(document).ready(function(){
	$('.messages > div').each(function(i, e){
		Notification($(e).html(), $(e).attr('class'));	
	});
});

$(document).ready(function(){
	$('.cb .cb-tab').click(function(){
		if(!$('.cb').hasClass('cb-open')){
			$('.cb').animate({'right': 290}, 300, function(){$('.cb').addClass('cb-open');});
		} else {
			$('.cb').animate({'right': -67}, 300, function(){$('.cb').removeClass('cb-open');});
		}
	});
	
	
});


  $(document).bind('click', function(e) {  

 var $clicked = $(e.target);

    if (!$clicked.parents().hasClass("cb")) {
        $('.cb').animate({'right': -67}, 300, function(){$('.cb').removeClass('cb-open');});
    }
	
});

	/* Ajax Cart */
 	$('.cart').live('hover', function() {
		$('.cart').addClass('active');
		
		$('.cart').load('index.php?route=module/cart .cart > *');
		
		$('.cart').live('mouseleave', function() {
			$(this).removeClass('active');
		});
	});
	

 
function getURLVar(key) {
	var value = [];
	
	var query = String(document.location).split('?');
	
	if (query[1]) {
		var part = query[1].split('&');

		for (i = 0; i < part.length; i++) {
			var data = part[i].split('=');
			
			if (data[0] && data[1]) {
				value[data[0]] = data[1];
			}
		}
		if (value[key]) {
			return value[key];
		} else {
			return '';
		}
	}
} 
	
	
	
	
